/*
 * File Name:               DemoListWindow.cs
 *
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/24
 */

using System.Collections.Generic;
using UnityEngine.UI;

public class DemoListWindow : UIWindow
{
    private Button mBtnClose;
    private UIContext mListCell;
    private UIListContainer mListVertical;
    private UIListContainer mListGridVertical;
    private UIListContainer mListHorizon;
    private UIListContainer mListGridHorizon;

    protected override void onCacheComponents()
    {
        mBtnClose = getComponent<Button>(0);
        mListCell = getComponent<UIContext>(1);
        mListVertical = getComponent<UIListContainer>(2);
        mListGridVertical = getComponent<UIListContainer>(3);
        mListHorizon = getComponent<UIListContainer>(4);
        mListGridHorizon = getComponent<UIListContainer>(5);
    }

    protected override void onClearComponents()
    {
        mBtnClose = null;
        mListCell = null;
        mListVertical = null;
        mListGridVertical = null;
        mListHorizon = null;
        mListGridHorizon = null;
    }

    protected override void onAddListeners()
    {
        mBtnClose.addListener(closeSelf);
    }

    protected override void onRemoveListeners()
    {
    }

    protected override void onOpen(object args)
    {
        mListCell.gameObject.SetActive(false);

        displayList(mListVertical, 1000);
        displayList(mListGridVertical, 1000);
        displayList(mListHorizon, 1000);
        displayList(mListGridHorizon, 1000);
    }

    protected override void onClose()
    {
    }

    private void displayList(UIListContainer container, int count)
    {
        var list = new List<UIListCell>();
        for (int i = 0; i < count; i++)
        {
            var cell = UIListView<DemoListCellView>.create(mListCell.gameObject, i);
            list.Add(cell);
        }
        container.setDatas(list);
        container.display();
    }
}